package cn.iocoder.yudao.adminserver.modules.fi.convert.coreTask;

import java.util.*;

import cn.iocoder.yudao.adminserver.modules.fi.dal.dataobject.project.ProjectDO;
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.adminserver.modules.fi.controller.coreTask.vo.*;
import cn.iocoder.yudao.adminserver.modules.fi.dal.dataobject.coreTask.CoreTaskDO;

/**
 * 项目反馈 Convert
 *
 * @author hickteam
 */
@Mapper
public interface CoreTaskConvert {

    CoreTaskConvert INSTANCE = Mappers.getMapper(CoreTaskConvert.class);

    CoreTaskDO convert(CoreTaskCreateReqVO bean);

    CoreTaskDO convert(CoreTaskUpdateReqVO bean);

    default CoreTaskRespVO convert(CoreTaskDO bean, Map<Long, SysUserDO> userMap, Map<Long, ProjectDO> projectMap){
        if ( bean == null ) {
            return null;
        }

        CoreTaskRespVO coreTaskRespVO = new CoreTaskRespVO();

        coreTaskRespVO.setName( bean.getName() );
        coreTaskRespVO.setMaintainId( bean.getMaintainId() );
        coreTaskRespVO.setDoTaskUid( bean.getDoTaskUid() );
        coreTaskRespVO.setProjectId( bean.getProjectId() );
        coreTaskRespVO.setIsFinish( bean.getIsFinish() );
        coreTaskRespVO.setCurrentLocation( bean.getCurrentLocation() );
        coreTaskRespVO.setFinishDate( bean.getFinishDate() );
        coreTaskRespVO.setTaskType( bean.getTaskType() );
        coreTaskRespVO.setEndTime( bean.getEndTime() );
        coreTaskRespVO.setDoTime( bean.getDoTime() );
        coreTaskRespVO.setId( bean.getId() );
        coreTaskRespVO.setCreateTime( bean.getCreateTime() );
        coreTaskRespVO.setDoImgList(bean.getDoImgList());
        coreTaskRespVO.setDoTaskDesc(bean.getDoTaskDesc());
        SysUserDO user = userMap.get(bean.getDoTaskUid());
        coreTaskRespVO.setDoTaskName(user == null ? "":user.getNickname());
        if(projectMap != null){
            ProjectDO pro = projectMap.get(bean.getProjectId());
            coreTaskRespVO.setProjectName(pro.getProjectName());
        }
        return coreTaskRespVO;
    }

    default List<CoreTaskRespVO> convertList(List<CoreTaskDO> list, Map<Long, SysUserDO> userMap){
        if ( list == null ) {
            return null;
        }

        List<CoreTaskRespVO> list1 = new ArrayList<CoreTaskRespVO>( list.size() );
        for ( CoreTaskDO coreTaskDO : list ) {
            list1.add( convert( coreTaskDO, userMap, null) );
        }

        return list1;
    }

    PageResult<CoreTaskRespVO> convertPage(PageResult<CoreTaskDO> page);

    List<CoreTaskExcelVO> convertList02(List<CoreTaskDO> list);

}
